<script setup lang="ts">
import type { TCourse, TSection } from '@/api/courses'
const dialogVisible = ref(false)

const initData = () => ({
  id: undefined,
  courseId: 0,
  courseName: '',
  sectionName: '',
  description: '',
  orderNum: 0,
  status: 0
})
const form = ref(initData())
const showAndInit = (course: TCourse, section: TSection | undefined) => {
  dialogVisible.value = true
  form.value = initData()
  form.value.courseName = course.courseName
  if (section) {
    Object.assign(form.value, section)
    console.log(form.value)
  }
  // console.log(course)
  console.log(section)
}
defineExpose({ showAndInit })
</script>

<template>
  <el-dialog v-model="dialogVisible" title="新建或更新章节" width="30%" :close-on-press-escape="false" :close-on-click-modal="false">
    <el-form :model="form" ref="formRef" label-width="80px" :inline="false" size="large">
      <el-form-item label="课程名称">
        <el-input v-model="form.courseName" autocomplete="off" disabled />
      </el-form-item>
      <el-form-item label="章节名称">
        <el-input v-model="form.sectionName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="章节描述">
        <el-input v-model="form.description" type="textarea" autocomplete="off" clearable />
      </el-form-item>
      <el-form-item label="章节排序">
        <el-input-number v-model="form.orderNum" controls-position="right" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="dialogVisible = false">立即创建</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style lang="scss" scoped></style>
